var _user = require("../../API/set.js"),_util = require("../../lib/utils/util.js");
var app = getApp();
Component({
    properties: {
        iShidden: {
            type: Boolean,
            value: !0
        },
    },
    data: {
        cloneIner: null,
        loading: !1,
        errorSum: 0,
        showAuthMobile: !1,
        code:'',
        userInfo:'',
        iShidden:1
    },
    attached: function() {
       this.setAuthStatus();
    },
    methods: {
        close:function(){
            this.setData({
                iShidden:1,
            })
        },
        setAuthStatus: function(e) {
            var self = this;
            wx.login({
                success (res) {
                  if (res.code) {
                    //发起网络请求
                    self.setData({
                       code:res.code
                   })
                   self.getWxUserInfo()
                  } else {
                    // console.log('登录失败！' + res.errMsg)
                  }
                }
              })
        },
        setUserInfo: function() {
            console.log('zoule')
            var a = this;
            wx.getUserProfile({
                lang:'zh_CN',
                desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
                success: (res) => {
                    console.log(res)
                    a.setData({
                        userInfo:res.userInfo
                    })
                    wx.login({
                        success (p) {
                          if (p.code) {
                            //发起网络请求
                            a.setData({
                               code:p.code
                           })
                          }
                          a.setAuthStatus()
                        },
                        
                      })
                },fail(p){
                    console.log(p)
                },
                complete(p){
                    console.log(p)
                },
              })
            
        },
        getWxUserInfo: function() {
            var a = this,e={};
            // console.log(e)
            if(!app.globalData.token){
                e.code = a.data.code,e.userInfo = a.data.userInfo,e.spid = app.globalData.spid, 
                e.spread_code = app.globalData.code, (0, _user.mpLogin)(e).then(function(t) {
                  console.log(t)
                  if(t.data.userInfo.nickname == '微信用户'||!t.data.userInfo.phone||t.data.userInfo.phone == ''){
                    wx.setStorage({
                      key: "startShow",
                      data: 1
                  })
                  }else{
                    wx.setStorage({
                      key: "startShow",
                      data: 0
                  })
                  };
                  console.log(t.data.userInfo);
                    app.globalData.token = t.data.token, app.globalData.isLog = !0, app.globalData.userInfo = t.data.userInfo, 
                    app.globalData.expiresTime = t.data.expires_time, t.data.cache_key && wx.setStorage({
                        key: "cache_key",
                        data: t.data.cache_key
                    }), wx.hideLoading(), a.setData({
                        iShidden: 1,
                        errorSum: 0
                    }), a.triggerEvent("onLoadFun", app.globalData.userInfo);
                }).catch(function(t) {
                    a.setData({
                        iShidden: 0,
                    })
                });
            }else{
                a.triggerEvent("onLoadFun", app.globalData.userInfo)
            }
                
        }
    }
});